package com.wjbgn.gobang.server.user.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjbgn.gobang.server.user.dto.GameLogDTO;
import com.wjbgn.gobang.server.user.entity.GameLogDO;
import com.wjbgn.gobang.server.utils.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 
 * Create Date: 2022-04-12T20:32:37.046
 * @author wjbgn
 * @version 1.0
 */
@Component
public class GameLogDoConvert {

    /**
     * DtoToDo
     *
     * @param gameLogDTO
     * @return
     */
    public static GameLogDO dtoToDo(GameLogDTO gameLogDTO) {
            GameLogDO gameLogDO = new GameLogDO();
        BeanCopierUtil.copy(gameLogDTO, gameLogDO);
        return gameLogDO;
    }

    /**
     * DoToDto
     *
     * @param gameLogDO
     * @return
     */
    public static GameLogDTO doToDto(GameLogDO gameLogDO) {
            GameLogDTO gameLogDTO = new GameLogDTO();
        BeanCopierUtil.copy(gameLogDO, gameLogDTO);
        return gameLogDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<GameLogDTO> pageConvert(Page<GameLogDO> pageDO) {
        List<GameLogDTO> list = listConvert(pageDO.getRecords());
        Page<GameLogDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<GameLogDTO> listConvert(List<GameLogDO> listDO) {
        List<GameLogDTO> list = new ArrayList<>();
            GameLogDTO gameLogDTO;
        for (GameLogDO gameLogDO : listDO) {
                gameLogDTO = new GameLogDTO();
            BeanCopierUtil.copy(gameLogDO, gameLogDTO);
            list.add(gameLogDTO);
        }
        return list;
    }
}